# -*- coding: utf-8 -*-
"""
Player() 返回的是一个玩家对象
函数：
    getpath:返回对应的牌的图片位置
    getsock:返回玩家持牌的分数
"""
from tkinter import *

class Poke_game:
    def __init__(self, master, player):
        self.name = player.name
        self.site = player.site

        self.path = player.path
        self.type = player.type
        self.sock = player.sock

        self.labelframe=LabelFrame(master,text="玩家:%s"%self.name,width=50)
        
        if self.site <= 3 :             
            self.labelframe.grid(row=0,column=self.site-1,padx=10,pady=10)  
        else:
            self.labelframe.grid(row=1,column=self.site-4)

        self.f0=Frame(self.labelframe)
        self.f0.pack()
        
        self.f1=Frame(self.f0)
        self.f1.pack(side=LEFT)
        self.f2=Frame(self.f0)
        self.f2.pack(side=LEFT)
        self.f3=Frame(self.f0)
        self.f3.pack(side=LEFT)

        self.f4=Frame(self.labelframe)
        self.f4.pack()

        self.vtype=StringVar()
        
        self.typelabel=Label(self.f4,textvariable=self.vtype,justify=LEFT)
        self.typelabel.grid(row=0,column=0)

        self.btext = StringVar()
        self.btext.set("看牌")
        self.b = Button(self.f4,textvariable=self.btext,command=self.show_poke)
        self.b.grid(row=0,column=1)

        self.vsock=StringVar()
        
        self.socklabel=Label(self.f4,textvariable=self.vsock,justify=LEFT)
        self.socklabel.grid(row=0,column=2)

        self.ready()

    def ready(self):        
        self.photo0 = PhotoImage(file=r'./pic/joker.png')

        path1=r'./pic/{}.png'.format(self.path)
        path2=r'./pic/{}.png'.format(self.path)
        path3=r'./pic/{}.png'.format(self.path)
        self.photo1 = PhotoImage(file=path1)
        self.photo2 = PhotoImage(file=path2)
        self.photo3 = PhotoImage(file=path3)
        
        self.l1a = Label(self.f1,image=self.photo0)
        self.l1a.pack()
        self.l1b = Label(self.f1,image=self.photo1)
        self.l1b.forget()

        self.l2a = Label(self.f2,image=self.photo0)
        self.l2a.pack()
        self.l2b = Label(self.f2,image=self.photo2)
        self.l2b.forget()

        self.l3a = Label(self.f3,image=self.photo0)
        self.l3a.pack()
        self.l3b = Label(self.f3,image=self.photo3)
        self.l3b.forget()

    def show_poke(self):        
        if self.l1a.winfo_viewable():
            self.l1a.forget()
            self.l1b.pack()
                                
            self.l2a.forget()
            self.l2b.pack()

            self.l3a.forget()
            self.l3b.pack()

            self.vtype.set("类型:%s"%self.type)
            self.vsock.set("分数:%s"%self.sock)
            self.btext.set("弃牌:")

        else:
            self.l1a.pack()
            self.l1b.forget()
                        
            self.l2a.pack()
            self.l2b.forget()

            self.l3a.pack()
            self.l3b.forget()

            self.btext.set("看牌:")

if __name__ == "__main__":
    root = Tk()
    root.title('poke game')
    root.geometry('695x400')
    class Player:
        def __init__(self,name,site):
            self.name = name
            self.site = site
            self.type = None
            self.path = r'joker'
            self.sock = None

    tom = Poke_game(root, Player('tom', 1))
    john = Poke_game(root, Player('john', 2))
    bob = Poke_game(root,Player('bob', 3))
    jobs = Poke_game(root,Player('jobs', 4))
    steven = Poke_game(root,Player('steven', 5))
    rose = Poke_game(root, Player('rose',6))

    mainloop()
